<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$time_start = getMicro_Time();
$intWebPercent = (int)$_KSysParam["NonTechSharePercent"];
$intTechPercent = (int)$_KSysParam["TechPercent"];
$intOpPercent = (int)$_KSysParam["OperatorPercent"];
$intTotalPercent = $intWebPercent + $intTechPercent + $intOpPercent;
$intTotalTechPercent = $intTechPercent + $intOpPercent;
if($intTotalPercent == 0)$intTotalPercent = 1;
$strSuppleReAccount = trim($_KSysParam["SuppleReAccount"]);
$isShowSuppleSystem = true;

include_once("Director_ListResult.php");

$time_end = getMicro_Time();
$fp = @file($strTemplatePath."Director_List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

$fp = str_replace("{Show_Lotto_Type}", $_data["LottoID"], $fp);
$fp = str_replace("{Show_GambleID}", $_data["GambleID"], $fp);
$fp = str_replace("{Show_Bet_Type}", $_data["Bet_Type"], $fp);
$fp = str_replace("{Show_PayupDate_0}", $data["PayupDate_x"][0], $fp);
$fp = str_replace("{Show_PayupDate_1}", $data["PayupDate_x"][1], $fp);
$fp = str_replace("{LottoContent}", (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
$fp = str_replace("{BetTypeContent}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_arrLotto[$_data["LottoID"]]["LType"]][$_data["Bet_Type"]], $fp);

while(list($k, $v) = each($_strAccount_Director)){
	$fp = str_replace("{".$k."}", $v, $fp);
}
if($intTotalTechPercent == 0){
	preg_replace("/<!--@ SuppleSystemTechResult Start @\/\/-->(.+)<!--@ SuppleSystemTechResult End @\/\/-->/s", "", $fp);
}
preg_match("/<!--@ SuppleSystemDirectorResult Start @\/\/-->(.+)<!--@ SuppleSystemDirectorResult End @\/\/-->/s", $fp, $TA);
preg_match("/<!--@ SuppleSystemTechResult Start @\/\/-->(.+)<!--@ SuppleSystemTechResult End @\/\/-->/s", $fp, $TSA);
preg_match("/<!--@ SuppleSystemCompanyResult Start @\/\/-->(.+)<!--@ SuppleSystemCompanyResult End @\/\/-->/s", $fp, $TG);

preg_match("/<!--@ SuppleDirectorResult Start @\/\/-->(.+)<!--@ SuppleDirectorResult End @\/\/-->/s", $fp, $SA);
preg_match("/<!--@ SuppleCompanyResult Start @\/\/-->(.+)<!--@ SuppleCompanyResult End @\/\/-->/s", $fp, $SG);
preg_match("/<!--@ DirectorResult Start @\/\/-->(.+)<!--@ DirectorResult End @\/\/-->/s", $fp, $A);
preg_match("/<!--@ CompanyResult Start @\/\/-->(.+)<!--@ CompanyResult End @\/\/-->/s", $fp, $G);
preg_match("/<!--@ ALLResult Start @\/\/-->(.+)<!--@ ALLResult End @\/\/-->/s", $fp, $S);
$sumtotals = 0;
$sumMemStake = 0;
$sumSubIncome = 0;
$sumSubRateResult = 0;
$sumMainRateResult = 0;
$sumStockRateResult = 0;
$sumrealMemStake = 0;
$sumDirectorRateResult = 0;
$Ctotals = 0;
$CMemStake = 0;
$CRealMemStake = 0;
$CDirectorRateResult = 0;
	if(is_array($arrRows[0])){
		while(list($k, $Rows) = each($arrRows[0])){
			$tmpA = $A[1];
			$DirectorID = $Rows -> DirectorID;
			//總帳
			if($intReportType == 0){
				$tmpA = str_replace("{Show_Director}", $arrAccount[$Rows -> DirectorID], $tmpA);
				if($isShowItem == false && $intDirectorID != $Rows -> DirectorID){
					$tmpA = str_replace("Account('{Show_DirectorID}')", "void(0);", $tmpA);
				}//else{
				//	if($intDirectorID == $Rows -> DirectorID)$tmpA = str_replace("crig", "crigplus", $tmpA);
					$tmpA = str_replace("{Show_DirectorID}", $Rows -> DirectorID, $tmpA);
				//}
			//分類帳
			}elseif($intReportType == 1){
				$tmpA = str_replace("{Show_Director}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
				$tmpA = str_replace("Account('{Show_DirectorID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."')", $tmpA);
			}
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f",$Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f",$Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f",$Rows -> realMemStake), $tmpA);
			$tmpA = str_replace("{realMemStake%}", sprintf("%.4f",$Rows -> realMemStake / $CrealMemStake), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f",$Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{StockRateResult}", sprintf("%.1f",$Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{DirectorRateResult}", sprintf("%.1f",$Rows -> DirectorRateResult), $tmpA);
			$strCon .= $tmpA;

			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumStockRateResult += $Rows -> StockRateResult;
			$sumrealMemStake += $Rows -> realMemStake;
			$sumDirectorRateResult += $Rows -> DirectorRateResult;

			$Ctotals += $Rows -> totals;
			$CComm += $Rows -> RealCommission;
			$CMemStake += $Rows -> MemStake;
			$CDirectorRateResult += $Rows -> DirectorRateResult;
			$CRealMemStake += $Rows -> realMemStake;
		}
	}
	$tmpG = str_replace("{Show_Director}",$arrAccount[$DirectorID], $G[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
	$tmpG = str_replace("{sumrealMemStake%}", sprintf("%.4f", $sumrealMemStake / $CrealMemStake), $tmpG);
	$tmpG = str_replace("{sumDirectorRateResult}", sprintf("%.1f", $sumDirectorRateResult), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ DirectorResult Start @\/\/-->.+<!--@ CompanyResult End @\/\/-->/s", $strCon, $fp);

	//補貨
	$strCon = "";
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumDirectorRateResult = 0;
	if(is_array($arrRows[1])){
		while(list($k, $Rows) = each($arrRows[1])){
			if($strSuppleReAccount != "" && preg_match("/".$strSuppleReAccount."/", $arrAccount[$Rows -> MemID])){
				$objSuppleRows = $Rows;
				continue;
			}
			$tmpA = $SA[1];
			$DirectorID = $Rows -> DirectorID;
			if($intReportType == 0){
				$tmpA = str_replace("{Show_Director}", $arrAccount[$Rows -> MemID], $tmpA);
				$tmpA = str_replace("{Show_DirectorID}", $Rows -> MemID, $tmpA);
			}elseif($intReportType == 1){
				$tmpA = str_replace("{Show_Director}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
				$tmpA = str_replace("BetSupple('{Show_DirectorID}')", "SuppleReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."')", $tmpA);
			}

			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{DirectorRateResult}", sprintf("%.1f",$Rows -> DirectorRateResult), $tmpA);
			$strCon .= $tmpA;

			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumDirectorRateResult += $Rows -> DirectorRateResult;

			$Ctotals += $Rows -> totals;
			$CComm += $Rows -> RealCommission;
			$CMemStake += $Rows -> MemStake;
			$CDirectorRateResult += $Rows -> DirectorRateResult;
			$CRealMemStake += $Rows -> MemStake;
		}
	}
	$tmpG = str_replace("{Show_Director}",$arrAccount[$DirectorID], $SG[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
	$tmpG = str_replace("{sumDirectorRateResult}", sprintf("%.1f", $sumDirectorRateResult), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ SuppleDirectorResult Start @\/\/-->.+<!--@ SuppleCompanyResult End @\/\/-->/s", $strCon, $fp);

	//系統補貨
	$strCon = "";
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumDirectorRateResult = 0;
	if(is_object($objSuppleRows)){
		$tmpA = $TA[1];
		$DirectorID = $objSuppleRows -> DirectorID;
		if($intReportType == 0){
			$tmpA = str_replace("{Show_Director}", $arrAccount[$objSuppleRows -> MemID], $tmpA);
			$tmpA = str_replace("{Show_DirectorID}", $objSuppleRows -> MemID, $tmpA);
		}elseif($intReportType == 1){
			$tmpA = str_replace("{Show_Director}", $_arrBet_Type[$_arrLotto[$objSuppleRows -> LottoID]["LType"]][$objSuppleRows -> Bet_Type], $tmpA);
			$tmpA = str_replace("BetSupple('{Show_DirectorID}')", "SuppleReportType('".$objSuppleRows -> LottoID."','".$objSuppleRows -> Bet_Type."')", $tmpA);
		}

		$tmpA = str_replace("{totals}", number_format($objSuppleRows -> totals), $tmpA);
		$tmpA = str_replace("{MemStake}", sprintf("%.1f", $objSuppleRows -> MemStake), $tmpA);
		$tmpA = str_replace("{DirectorRateResult}", sprintf("%.1f", $objSuppleRows -> DirectorRateResult), $tmpA);
		$strCon .= $tmpA;

		$sumtotals += $objSuppleRows -> totals;
		$sumMemStake += $objSuppleRows -> MemStake;
		$sumDirectorRateResult += $objSuppleRows -> DirectorRateResult;

		$Ctotals += $objSuppleRows -> totals;
		$CComm += $objSuppleRows -> RealCommission;
		$CMemStake += $objSuppleRows -> MemStake;
		$CDirectorRateResult += $objSuppleRows -> DirectorRateResult;
		$CRealMemStake += $objSuppleRows -> MemStake;
	}

	//技術股
	/*$tolTechStake = 0;
	$tolTechResult = 0;
	if($intTotalTechPercent > 0){
		$arrTmp = array();
		if($_SESSION["Admin_Info"] -> MemberGroup > 32 || $_SESSION["Admin_Info"] -> MemberGroup < 30){
			$arrName = array($_strAccount_Director["OpShare"]);
			$arrTmp[0] = round(($intTotalTechPercent / $intTotalPercent)*100, 4);
		}else{
			$arrName = array($_strAccount_Director["OpShare"], $_strAccount_Director["TechShare"]);
			$arrTmp[0] = round(($intOpPercent / $intTotalPercent)*100, 4);
			$arrTmp[1] = round(($intTechPercent / $intTotalPercent)*100, 4);
		}
		foreach($arrTmp as $intKey => $flTmp){
			$flTechResult = sprintf("%.1f", -1 * $flTmp * $CDirectorRateResult / 100);
			$flTechStake = sprintf("%.0f", -1 * $flTmp * $CRealMemStake / 100);
			$tmpA = $TSA[1];
			$tmpA = str_replace("{Show_Director}", $arrName[$intKey], $tmpA);
			$tmpA = str_replace("{ShowTechPercent}", $flTmp."%", $tmpA);
			$tmpA = str_replace("{ShowTechStake}", $flTechStake, $tmpA);
			$tmpA = str_replace("{DirectorRateResult}", $flTechResult, $tmpA);
			$strCon .= $tmpA;
			$tolTechResult += $flTechResult;
			$tolTechStake += $flTechStake;
		}
		$CDirectorRateResult += $tolTechResult;
		$sumDirectorRateResult += $tolTechResult;
	}*/
$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $TG[1]);
$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
$tmpG = str_replace("{sumTechStake}", sprintf("%.1f", $sumMemStake + $tolTechStake), $tmpG);
$tmpG = str_replace("{sumDirectorRateResult}", sprintf("%.1f", $sumDirectorRateResult), $tmpG);
$strCon .= $tmpG;
$fp = preg_replace("/<!--@ SuppleSystemDirectorResult Start @\/\/-->.+<!--@ SuppleSystemCompanyResult End @\/\/-->/s", $strCon, $fp);

//總匯
$tmpS = str_replace("{Ctotals}", number_format($Ctotals), $S[1]);
$tmpS = str_replace("{CMemStake}", sprintf("%.1f", $CMemStake), $tmpS);
$tmpS = str_replace("{CComm}", sprintf("%.1f", $CComm), $tmpS);
$tmpS = str_replace("{CWinLose}", sprintf("%.1f", ($CDirectorRateResult - $CComm)), $tmpS);
$tmpS = str_replace("{CDirectorRateResult}", sprintf("%.1f", $CDirectorRateResult), $tmpS);
$fp = preg_replace("/<!--@ ALLResult Start @\/\/-->.+<!--@ ALLResult End @\/\/-->/s", $tmpS, $fp);

$fp .= "\n<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";
//輸出
WebOutputHTML($fp, 1);
?>